<template>
  <div>
    <div id="container">
      <header>
        <h1>蜗牛学院学生管理系统</h1>
      </header>
      <main>
        <div class="section-content form-content">
          <div class="content">
            <div class="content-info">
              <h3>用户登录</h3>
              <div>
                <div>
                  <div class="content-row">
                    <label>登录账号：</label>
                    <input
                      class="form-input"
                      type="text"
                      id="username"
                      v-model.lazy="user.username"
                    />
                  </div>
                  <div class="content-row">
                    <label>登录密码：</label>
                    <input
                      class="form-input"
                      type="text"
                      id="password"
                      v-model.lazy="user.password"
                    />
                  </div>
                  <div class="content-row" style="margin-top: 50px">
                    <label></label>
                    <button class="blue" id="loginBtn" @click="login()">
                      登录
                    </button>
                    <router-link to="/register">么有账号？去注册</router-link>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </main>
    </div>
    <!-- <h1>登陆</h1>
       <button @click="login">点击注册</button>
      <router-link to="/register">么有账号？去登陆</router-link> -->
  </div>
</template>

<script>
// import axios from "axios";
import api from "../http/api";

export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  mounted() {
    console.log(this.$route.query);
  },
  methods: {
    async login() {
      //发送请求获取学生数据
      const data = await api.users.login(this.user);
// console.log(this.data);
      console.log(data);
      if (data.code) {
        alert("登陆成功");
        localStorage.token = data.token;
        this.$router.push("/Home");
      }
    },
  },
};
</script>

<style>
</style>